The following example shows how to fabricate a hierarchical Recordset without an underlying data source by using the data shaping grammar to define columns for parent, child, and grandchild recordsets.
To fabricate a hierarchical Recordset, you must specify the Microsoft Data Shaping Service for OLE DB (MSDataShape) and a Data Provider value of NONE in the connection string parameter of the Connection object's Open method. Refer to Required Providers for Data Shaping for more information.
Dim cn As New ADODB.Connection
Dim rsCustomers As New ADODB.Recordset
cn.Open "Provider=MSDataShape;Data Provider=NONE;"
strShape = _
"SHAPE APPEND NEW adInteger AS CustID," & _
" NEW adChar(25) AS FirstName," & _
" NEW adChar(25) AS LastName," & _
" NEW adChar(12) AS SSN," & _
" NEW adChar(50) AS Address," & _
" ((SHAPE APPEND NEW adChar(80) AS VIN_NO," & _
" NEW adInteger AS CustID," & _
" NEW adChar(20) AS BodyColor, " & _
" ((SHAPE APPEND NEW adChar(80) AS VIN_NO," & _
" NEW adChar(20) AS Make, " & _
" NEW adChar(20) AS Model," & _
" NEW adChar(4) AS Year) " & _
" AS VINS RELATE VIN_NO TO VIN_NO))" & _
" AS Vehicles RELATE CustID TO CustID) "
rsCustomers.Open strShape, cn, adOpenStatic, adLockOptimistic, -1
Once the Recordset has been fabricated, it can be populated, manipulated, or persisted to a file.